/**
 * @description 手机号工具类
 *
 * 根据手机号获取户籍
 * @author cx
 * @date 2024.08.12 15:13
 */
package com.cx.utils;


import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
import com.google.i18n.phonenumbers.Phonenumber;
import com.google.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;

import java.util.Locale;

public class PhoneUtil {

    public static String getAddressByPhone(String phone) {
        PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
        PhoneNumberOfflineGeocoder phoneNumberOfflineGeocoder = PhoneNumberOfflineGeocoder.getInstance();
        String language = "CN";
        Phonenumber.PhoneNumber referencePhonenumber = null;

        String phoneNum = phone;
        try {
            referencePhonenumber = phoneUtil.parse(phoneNum, language);
        } catch (NumberParseException e) {
            e.printStackTrace();
        }
        String city = phoneNumberOfflineGeocoder.getDescriptionForNumber(referencePhonenumber, Locale.CHINA);
        return city;
    }

    public static void main(String[] args) {
        String addressByPhone = getAddressByPhone("15073246214");
        System.out.println(addressByPhone);

    }
}
